<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>视频管理</el-breadcrumb-item>
      <el-breadcrumb-item>修改视频</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form label-width="80px" :model="editVideoForm" :rules="editVideoRules" ref="editVideoRef">
      <el-row>
        <el-col :span="7">
          <el-form-item label="视频标题" prop="video_title">
            <el-input prefix-icon="el-icon-user-solid" v-model="editVideoForm.video_title"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7">
          <el-form-item label="分类">
            <el-input prefix-icon="el-icon-lock" disabled v-model="editVideoForm.category"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7">
          <el-form-item label="视频" prop="src">
            <video :src="editVideoForm.src"></video>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7">
          <el-form-item>
            <el-button type="primary" size="mini" @click="editSetVideoForm">修改</el-button>
            <el-button type="warning" size="mini" @click="reseteditVideoForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getVideosById, putVideoById } from "@/api/data";
export default {
  data() {
    return {
      editVideoForm: {},
      // 验证规则
      editVideoRules: {
        video_title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        category: [
          { required: true, message: "分类不能为空", trigger: "blur" }
        ],
        src: [{ required: true, message: "视频不能为空", trigger: "blur" }]
      }
    };
  },
  created() {
    this.getVideoInfo();
  },
  methods: {
    reseteditVideoForm() {
      this.$refs.editVideoRef.resetFields();
    },
    async getVideoInfo() {
      let { data: res } = await getVideosById(this.$route.params.id);
      // let { data: res } = await this.$http.get(
      //   "videos/" + this.$route.params.id
      // );
      this.editVideoForm = res.data;
    },
    async editSetVideoForm() {
      await putVideoById(this.$route.params.id, this.editVideoForm);
      // await this.$http.put(
      //   "videos/" + this.$route.params.id,
      //   this.editVideoForm
      // );
      this.$message.success({ message: "修改成功", duration: 1000 });
      this.$router.push("/video/list");
    }
  }
};
</script>

<style>
</style>